package com.redwood.report.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.redwood.report.common.Constant;
import com.redwood.report.event.NetworkChangeEvent;
import com.redwood.report.util.Utils;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Supeng on 2018/8/15.
 * 网络变化Recevier
 */

public class NetworkConnectChangedReceiver extends BroadcastReceiver {
    private static final String TAG = "NetworkConnectChanged";
    @Override
    public void onReceive(Context context, Intent intent) {
        //**判断当前的网络连接状态是否可用*/
        boolean isConnected = Utils.isConnected(context);
        if(isConnected!= Constant.isNetWorkOn) {
            Log.d(TAG, "onReceive: 当前网络 " + isConnected);
            Constant.isNetWorkOn=isConnected;
            EventBus.getDefault().post(new NetworkChangeEvent(isConnected));
        }
    }
}
